package cn.seaboot;

import cn.seaboot.flake.core.PreparedSql;
import cn.seaboot.flake.core.SqlHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * 基本功能
 *
 * @author Mr.css
 * @version 2025-05-21 10:12
 */
public class Example {
    public static void main(String[] args) {
        SqlHelper help = new SqlHelper();

        String sql =
                "select * from table where id = #{id} " +
                "<% if(name != null && name != ''){%> and name = #{name} <%}%>" +
                "<% if(age >= 18){%> and age > #{age} <%}%>";

        // 参数
        Map<String, Object> params = new HashMap<>();
        params.put("id", "1");
        params.put("name", null);
        params.put("age", 18);

        PreparedSql ret = help.process(sql, params);
        System.out.println(ret);

        // 执行结果:
        // SQL         ===>: select * from table where id = ? and age > ?
        // Parameters  ===>: [1, 18]
    }
}
